package com.medical.service.impl;

import com.medical.entity.AdminEntity;
import com.medical.mapper.AdminMapper;
import com.medical.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public AdminEntity login(String adminAccount, String adminPassword) {
        return adminMapper.findByAdminAccountAndUserPassword(adminAccount, adminPassword);
    }

    @Override
    public boolean register(String adminAccount, String adminPassword) {
        AdminEntity  existingadmin= adminMapper.findByAdminAccount(adminAccount);
        if (existingadmin != null) {
            return false;
        } else {
            adminMapper.insertAdmin(adminAccount, adminPassword); // 保存新用户到数据库
            return true; // 注册成功
        }
    }

    @Override
    public List<AdminEntity> selectList() {
        return adminMapper.selectList();
    }

    @Override
    public int update(AdminEntity adminEntity) {
        return adminMapper.update(adminEntity);
    }

    @Override
    public boolean delete(String adminEntity) {
        return adminMapper.delete(adminEntity);
    }
}
